﻿CREATE TABLE [dbo].[aspnet_Roles] (
    [ApplicationId]   UNIQUEIDENTIFIER NOT NULL,
    [RoleId]          UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [RoleName]        NVARCHAR (256)   NOT NULL,
    [LoweredRoleName] NVARCHAR (256)   NOT NULL,
    [Description]     NVARCHAR (256)   NULL,
    [System]          BIT              CONSTRAINT [DF_aspnet_Roles_System] DEFAULT ((0)) NULL,
    PRIMARY KEY NONCLUSTERED ([RoleId] ASC),
    CONSTRAINT [FK__aspnet_Ro__Appli__1DE63FD0] FOREIGN KEY ([ApplicationId]) REFERENCES [dbo].[aspnet_Applications] ([ApplicationId])
);


GO
CREATE UNIQUE CLUSTERED INDEX [aspnet_Roles_index1]
    ON [dbo].[aspnet_Roles]([ApplicationId] ASC, [LoweredRoleName] ASC);


GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER [dbo].[aspnet_RoleDelete]
   ON  [dbo].[aspnet_Roles]
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @deSters smallint
	SET @deSters = 0
	SELECT @deSters = Count(*) from [Deleted] WHERE [System] = 1
	IF @deSters<>0
		GOTO Error1

    GOTO Gata
	Error1:
		RAISERROR ('Rolul nu poate fi stears deoarece apartine sistemului!', 16, 1)
		ROLLBACK TRANSACTION
	Gata:

END